package me.chan.nio.channel;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

@Slf4j
public class WritableClient {

    public static void main(String[] args) throws IOException {

        SocketChannel sc = SocketChannel.open();
        sc.connect(new InetSocketAddress("127.0.0.1", 8080));


        int read = 0;
        while (true) {
            ByteBuffer buffer = ByteBuffer.allocate(1024*1024);     // 1 MiB
//            if (sc.read(buffer) <= 0)
//                break;

            read += sc.read(buffer);        // sum up read data
            log.info("{} bytes data read", read);
            buffer.clear();
        }


    }
}
